import {onMounted, reactive} from "vue";
import axios from "axios";

export default function  () {
    let dogList = reactive([
        'https://images.dog.ceo/breeds/pembroke/n02113023_209.jpg'
    ])
    async function getDog() {
        try {
            let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
            // console.log(result)
            // console.log(result.data.message)
            dogList.push(result.data.message)
        }catch (e) {
            alert('接口请求错误' + e)
        }
    }

    onMounted(() => {
        getDog()
    })
    //向外部提供东西
    return {dogList,getDog}
}

// export function getDog () {
//     let dogList = reactive([
//         'https://images.dog.ceo/breeds/pembroke/n02113023_209.jpg'
//     ])
//
//     async function getDog() {
//         try {
//             let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
//             // console.log(result)
//             // console.log(result.data.message)
//             dogList.push(result.data.message)
//         }catch (e) {
//             alert('接口请求错误' + e)
//         }
//     }
// }
//export default 后面直接跟值